<template>
  <!-- This footer should be hidden by default and shown when there are todos -->
  <footer class="footer">
    <!-- This should be `0 items left` by default -->
    <span class="todo-count"
      ><strong>{{ total }}</strong> item left</span
    >
    <!-- Remove this if you don't implement routing -->
    <ul class="filters" @click="change">
      <li>
        <a :class="{ selected: type == 'all' }" href="#/" @click="type = 'all'"
          >All</a
        >
      </li>
      <li>
        <a
          :calss="{ selsected: type == 'no' }"
          @click="type = 'no'"
          href="#/active"
          >Active</a
        >
      </li>
      <li>
        <a
          :calss="{ selsected: type == 'yes' }"
          @click="type = 'yes'"
          href="#/completed"
          >Completed</a
        >
      </li>
    </ul>
    <!-- Hidden if no completed items are left ↓ -->
    <button class="clear-completed" @click="clear" v-if="hasDoneTodo">Clear completed</button>
  </footer>
</template>

<script>
export default {
  methods: {
    change() {
        this.$emit("switch-todo",this.type)
    },
    clear(){
        if(confirm("确认清空已完成事项么?")){
        this.$emit("clearFn")

        }
    }
  },
  data() {
    return {
      type: "all", //no yes
    };
  },
  props: ["arr"],
  computed: {
    total() {
      return this.arr.filter((item) => item.isDone === false).length;
    },
    hasDoneTodo(){
        return this.arr.some(item => item.isDone==true)
    }
  },
};
</script>

<style>
</style>